package cn.online.service;

import java.util.List;

import cn.online.dao.CourseDao;
import cn.online.dao.ProblemDao;
import cn.online.dao.ReplyDao;
import cn.online.model.Course;
import cn.online.model.Problem;

public class ProblemService {
	
	private ProblemDao problemDao;
	private CourseDao courseDao;
	private ReplyDao replyDao;
	
	public void setProblemDao(ProblemDao problemDao) {
		this.problemDao = problemDao;
	}
	public void setCourseDao(CourseDao courseDao) {
		this.courseDao = courseDao;
	}
	public void setReplyDao(ReplyDao replyDao) {
		this.replyDao = replyDao;
	}
	
	public void insert(Problem problem){
		//Course course=courseDao.findById(id);
		if(problem!=null ){
			//problem.setCourse(course);
			problem.setPdate(new java.util.Date());
			problem.setPfinish(0);
			problemDao.save(problem);
		}
	}
	
	public void update(Problem problem){
		if(problem!=null){
			problem.setPdate(new java.util.Date());
			problemDao.update(problem);
		}
	}
	
	public void delete(Integer id){
		Problem problem = problemDao.findById(id);
		if(problem!=null){
			replyDao.deleteReplyByProblemId(id);
			problemDao.delete(problem);
		}
	}
	
	public Problem findByid(Integer id){
		return problemDao.findById(id);
	}
	
	public List<Problem> getListByCourseId(Integer id){
		return problemDao.getProblemByCourseId(id);
	}
	
	public List<Problem> getListByFinish(Integer id){
		return problemDao.getProblemByCourseId(id,1);
	}
	public List<Problem> getListByNew(Integer id){
		return problemDao.getProblemByCourseId(id,0);
	}
	public List<Problem> getListNew(){
		return problemDao.getNewProblems();
	}
}
